package com.linlong.linlongchat.handler;

import com.alibaba.fastjson.JSON;
import com.linlong.linlongchat.IMService;
import com.linlong.linlongchat.domain.websocket.data.Command;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ApplyHandler {
    public static void execute(ChannelHandlerContext ctx, TextWebSocketFrame frame) {
        Command command = JSON.parseObject(frame.text(), Command.class);
        Channel channel = IMService.USERS.get(command.getTargetId());
        log.info("收到申请消息，目标ID：{}", command.getTargetId());
        channel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(command)));
    }
}
